package com.allwees.core.common.util.http;

import com.allwees.core.common.constant.EPlatform;
import lombok.Setter;
import lombok.ToString;

import java.util.Locale;
import java.util.ResourceBundle;

public class RequestContext {

    private static ThreadLocal<RequestInfo> context = new ThreadLocal<>();

    public static void setContext(RequestInfo info) {
        context.set(info);
    }

    public static void removeContext() {
        context.remove();
    }

    public static RequestInfo getContext() {
        return context.get();
    }

    public static EPlatform getPlatform(){
        return context.get().getPlatform();
    }

    public static String getAppVersion(){
        return context.get().getAppVersion();
    }

    public static String getChannel(){
        return context.get().getChannel();
    }

    public static String getRemoteAddr(){
        return context.get().getRemoteAddr();
    }

    public static boolean isEnLocale(){
        return Locale.ENGLISH.equals(context.get().getLocale());
    }

    @Setter
    @ToString
    public static class RequestInfo {
        private String agent;
        private EPlatform platform;
        private String appVersion;
        private String promChannel;
        private String channel;
        private String apiVersion;
        private Locale locale;
        private String remoteAddr;
        private String path;
        private ResourceBundle resourceBundle;

        public String getAgent() {
            return agent;
        }

        EPlatform getPlatform() {
            return platform;
        }

        String getAppVersion() {
            return appVersion;
        }

        String getPromChannel() {
            return promChannel;
        }

        String getChannel() {
            return channel;
        }

        String getApiVersion() {
            return apiVersion;
        }

        Locale getLocale() {
            return locale;
        }

        String getRemoteAddr() {
            return remoteAddr;
        }

        String getPath() {
            return path;
        }

        public ResourceBundle getResourceBundle() {
            return resourceBundle;
        }
    }
}
